/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Tactics;

import IO.Utils;
import Map.MapLevel;
import Map.MapUtils;
import Monsters.Monster;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 *
 * @author insane
 */
public class Movement {

    private static Movement instance;

    public static Movement getInstance() {
        if (instance == null) {
            instance = new Movement();
        }
        return instance;
    }

    private Movement() {
    }

    public void action(Monster ms) throws FileNotFoundException, IOException, ClassNotFoundException {
        switch (Utils.rand(0, 4)) {
            case 1:
                if (!MapUtils.checkMove(MapLevel.getInstance().getMap().getMap(), ms.getX() + 1, ms.getY())
                        && !(ms.getX() + 1 == MapLevel.getInstance().getMap().x && ms.getY() == MapLevel.getInstance().getMap().y)) {
                    ms.setX(ms.getX() + 1);
                } else {
                    action(ms);
                }
                break;
            case 2:
                if (!MapUtils.checkMove(MapLevel.getInstance().getMap().getMap(), ms.getX() - 1, ms.getY())
                        && !(ms.getX() - 1 == MapLevel.getInstance().getMap().x && ms.getY() == MapLevel.getInstance().getMap().y)) {
                    ms.setX(ms.getX() - 1);
                } else {
                    action(ms);
                }
                break;
            case 3:
                if (!MapUtils.checkMove(MapLevel.getInstance().getMap().getMap(), ms.getX(), ms.getY() + 1)
                        && !(ms.getX() == MapLevel.getInstance().getMap().x && ms.getY() + 1 == MapLevel.getInstance().getMap().y)) {
                    ms.setY(ms.getY() + 1);
                } else {
                    action(ms);
                }
                break;
            case 4:
                if (!MapUtils.checkMove(MapLevel.getInstance().getMap().getMap(), ms.getX(), ms.getY() - 1)
                        && !(ms.getX() == MapLevel.getInstance().getMap().x && ms.getY() - 1 == MapLevel.getInstance().getMap().y)) {
                    ms.setY(ms.getY() - 1);
                } else {
                    action(ms);
                }
                break;
        }

    }
}
